home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et-2_2.lha / et2.2 / src / ObjArray.h < prev    next >
C/C++ Source or Header  |  1990-11-28  |  2KB  |  89 lines

  1. #ifndef ObjArray_First
  2. #ifdef __GNUG__
  3. #pragma once
  4. #endif
  5. #define ObjArray_First
  6.  
  7. #include "Collection.h"
  8.  
  9. extern char *cOutOfBoundsError;
  10. extern char *cMethodName;
  11.  
  12. //---- class ObjArray --------------------------------------------------
  13.  
  14. class ObjArray: public Collection {
  15. friend class ObjArrayIter;
  16. friend class OrdCollection;
  17.     ObjPtr *cont;
  18.     int  lb; // lower bound of the array
  19.     bool BoundsOk(char *where, int at)
  20.     { if ( at < lb || at-lb >= Size()) {
  21.         Error(where, cOutOfBoundsError, at, Size(), (int)this);
  22.         return FALSE;
  23.       }
  24.       else
  25.         return TRUE;
  26.     }        
  27. public:  
  28.     MetaDef(ObjArray);
  29.  
  30.     //---- creation, destruction  
  31.     ObjArray(int s= cCollectionInitCap, int lowerBound= 0); 
  32.     ~ObjArray();
  33.     void InitNew();              
  34.     void Expand (int);              // expand or shrink an array
  35.     ObjPtr Add(ObjPtr);
  36.     void FreeAll();
  37.     
  38.     //---- accessing
  39.     Iterator *MakeIterator();           // return a Iterator iterator of a collection
  40.     int IndexOfPtr (ObjPtr);     // returns -1 if not found     
  41.     int IndexOf (ObjPtr);        //        "           "
  42.     ObjPtr At(int i);
  43.     ObjPtr AtPut(int i, ObjPtr op);
  44.     void AtPutAndExpand(int i, ObjPtr op);// expands the array if necessary
  45.     ObjPtr& operator[](int i)       // shorthand notation
  46.     { 
  47.         if ( i < lb || i-lb >= size)
  48.         Error(cMethodName, cOutOfBoundsError, i, size, this);
  49.         return cont[i-lb]; 
  50.     }
  51.     ObjPtr UncheckedAt(int i)
  52.     { return cont[i]; }
  53.     ObjPtr RemoveAt(int i);   
  54.     ObjPtr Remove(ObjPtr a);
  55.     ObjPtr RemovePtr(ObjPtr a);
  56.     int LowerBound()
  57.     { return lb; }
  58.     void Sort(int upto = cMaxInt);
  59.     int BinarySearch(ObjPtr, int upto = cMaxInt);
  60.     // the ObjArray has to be sorted, -1 == not found !!
  61.  
  62.     //---- comparing   
  63.     unsigned long Hash ();
  64.     bool IsEqual (ObjPtr);
  65.     int  Compare (ObjPtr);
  66.  
  67.     //---- activation/passivation
  68.     ostream& PrintOn(ostream&s);
  69.     istream& ReadFrom(istream&s);
  70. };
  71.  
  72. class ObjArrayIter: public Iterator {
  73.     int ce;
  74.     ObjArray *cs;
  75. public:
  76.     ObjArrayIter(Collection *s);
  77.     ~ObjArrayIter();
  78.     
  79.     void Reset(Collection *c= 0);
  80.     ObjPtr operator()();
  81.     virtual bool Filter(ObjPtr);
  82.  
  83.     //---- memory allocation
  84.     void *operator new (size_t);
  85.     void operator delete(void *vp);
  86. };
  87.  
  88. #endif ObjArray_First
  89.